package com.logger;

import com.logger.loader.ConfigLoader;

/**
 * logger工厂
 * Created by chenxunlin01 on 2016/1/16.
 */

public class LoggerFactory {

    static ConfigLoader loader;
    static Logger rootLogger;

    static {
        loader = new ConfigLoader();
        try {
            loader.initConfig();
        } catch (Exception e) {
            e.printStackTrace();
        }

        rootLogger = getRootLogger();
    }

    public static synchronized Logger getLogger(String tag) {
        Option option = Logger.config.getOption(tag);
        return new MLogger(option, tag);
    }

    public static Logger getRootLogger() {
        return new MLogger(Logger.config.getRoot(), "MLogger");
    }

    private static Option getOption(LoggerConfig config, String tag) {
        Option option = config.getOption(tag);
        if (option == null) {
            option = config.getRoot();
        }
        return option;
    }
}
